<template>
	<view>
		<u-navbar :is-fixed="false" :is-fun="false" :border-bottom="false" :is-back="false" title="Login"
			:background="{ background:'#F4F4F4'}">
		</u-navbar>
		<view class="body">
			<view class="" style="text-align: center;">
				<image src="../../static/logo.png" mode="widthFix" style="width: 60%;"></image>
			</view>
			<u-form :model="form" ref="uForm">
				<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" left-icon="facebook-circle-fill"
					prop="userName">
					<u-input v-model="form.userName" placeholder="请输入账号" />
				</u-form-item>
				<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" left-icon="lock-fill" prop="passWord">
					<u-input v-model="form.passWord" type="password" placeholder="请输入密码" />
				</u-form-item>
			</u-form>
			<view style="margin: 20px 0;">
				<u-button shape="circle" @click="submit()" type="primary">登录</u-button>
			</view>
			<view>
				<!-- <u-button shape="circle" @click="res()">注册</u-button> -->
			</view>
			<!-- <view style="color: #18B566;margin-top: 20px;text-align: right;" @click="resetPwd">重置密码</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					userName: '',//admin
					passWord: '',//654321
				},
				rules: {
					userName: [{
						required: true,
						message: '请输入账号',
						trigger: ['change', 'blur'], // 可以单个或者同时写两个触发验证方式 
					}],
					passWord: [{
						min: 6,
						required: true,
						message: '密码不能少于6个字符',
						trigger: ['change', 'blur'],
					}]
				}
			};
		},
		methods: {
			res() {},
			submit() {
				let _this=this
				this.$refs.uForm.validate(valid => {
					if (valid) {
						wx.getUserProfile({
							desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
							success: (res) => {
								uni.setStorageSync('wxInfo',JSON.stringify(res.userInfo));
								console.log(res.userInfo)
								this.updata()
							}
						})
					} else {
						uni.showToast({
							title: '账号/密码不能为空',
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
			updata(){
				this.$axios.post('Tuser/XCheckUser', this.form, p => {
					console.log(p)
					this.form.ID = p.data.ID+''
					uni.setStorageSync('userInfo', JSON.stringify(this.form))
					let app=getApp()
					app.globalData.timeFun()()
					console.log(app.globalData.timeFun)
					uni.switchTab({
						url: '../home/index'
					})
				})
			},
			
		},

		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onLoad() {

		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	};
</script>
<style lang="scss">
	.body {
		padding: 0 40rpx;
	}
</style>
